﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AgencyEntityLib.BaseEntity;
using Ecopsy.DataTier;

public partial class CRM_Frame : iPageController 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MyBind();
        }
    }
    private TreeNode NewBranch(TreeDictionaryItem Node, string sUrl)
    {

        TreeNode child = new TreeNode();
        string sid = Node.ID.Replace("-", string.Empty);

        string s = sUrl + "?CtegoriaID=" + Node.ID;
        child.Text = "<a class=TreeNode ID=" + sid + " href=\"#\" ID=Clients   onclick=\"showTreeBranch('" + s + "','" + sid + "');\"> " + Node.Name + " </a>";
        return child;

    }
    private void MyBind()
    {

        TreeDictionaryItem ClientStatus = iPageController.TreeDictionaryContext.GetClientStatus();
        TreeDictionaryItem TaskCategory = iPageController.TreeDictionaryContext.GetTaskCategory();

        tvCrm.Nodes.Clear();
        TreeNode Root = new TreeNode();
        Root.Text = "<a class=TreeNode> Управление </a>";

        TreeNode child = new TreeNode();
        child.Text = "<a class=TreeNode href=\"#\" ID=Calendar   onclick=\"showTreeBranch('iCRM_Calendar.aspx','Calendar');\"> " + "Календарь" + " </a>";
        Root.ChildNodes.Add(child);

        child = new TreeNode();
        child.Text = "<a class=TreeNode href=\"#\" ID=Contacts   onclick=\"showTreeBranch('iCRM_ContactFaces.aspx','Contacts');\"> " + "Контакты" + " </a>";
        Root.ChildNodes.Add(child);

        child = new TreeNode();
        child.Text = "<a class=TreeNode href=\"#\" ID=Clients   onclick=\"showTreeBranch('iCRM_Clients.aspx','Clients');\"> " + "Все организации" + " </a>";

        foreach (TreeDictionaryItem item in ClientStatus.ChildNodes)
        {
            child.ChildNodes.Add(NewBranch(item, "iCRM_Clients.aspx"));
        }

        Root.ChildNodes.Add(child);

        child = new TreeNode();
        child.Text = "<a ID=Tasks class=TreeNode href=\"#\" ID=Tasks   onclick=\"showTreeBranch('iCRM_Tasks.aspx','Tasks');\"> " + "Задачи" + " </a>";
        Root.ChildNodes.Add(child);

        foreach (TreeDictionaryItem item in TaskCategory.ChildNodes)
        {
            child.ChildNodes.Add(NewBranch(item, "iCRM_Tasks.aspx"));
        }

        tvCrm.Nodes.Add(Root);

    }
}
